package it.blueocean.acanto.web.platform.components.repeaters;

import java.util.List;

import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.OddEvenItem;
import org.apache.wicket.model.IModel;

public class AcantoDefaultDataTable<T> extends AjaxFallbackDefaultDataTable<T>
{
	private static final long serialVersionUID = 3295341125087305396L;

	private static int DEFAULT_NUM_ROWS_PER_PAGE = 5;
	
//	private final WebMarkupContainer filters;
	
	/**
	 * Constructor
	 * 
	 * @param id component id
	 * @param columns list of columns
	 * @param dataProvider data provider
	 * @param rowsPerPage number of rows per page
	 */
	@SuppressWarnings("unchecked")
	public AcantoDefaultDataTable(String id, final List<IColumn<T>> columns, ISortableDataProvider<T> dataProvider, int rowsPerPage)
	{
		this(id, columns.toArray(new IColumn[columns.size()]), dataProvider, rowsPerPage);
	}
	
	@SuppressWarnings("unchecked")
	public AcantoDefaultDataTable(String id, final List<IColumn<T>> columns, ISortableDataProvider<T> dataProvider)
	{
		this(id, columns.toArray(new IColumn[columns.size()]), dataProvider, DEFAULT_NUM_ROWS_PER_PAGE);
	}

	public AcantoDefaultDataTable(String id, final IColumn<T>[] columns, ISortableDataProvider<T> dataProvider)
	{
		this(id, columns, dataProvider, DEFAULT_NUM_ROWS_PER_PAGE);
	}
	
	/**
	 * Constructor
	 * 
	 * @param id component id
	 * @param columns array of columns
	 * @param dataProvider data provider
	 * @param rowsPerPage number of rows per page
	 */
	public AcantoDefaultDataTable(String id, final IColumn<T>[] columns, ISortableDataProvider<T> dataProvider, int rowsPerPage)
	{
		super(id, columns, dataProvider, rowsPerPage);
		setOutputMarkupId(true);
		setVersioned(true);
		addBottomToolbar(new AcantoNavigationToolbar(this));
		addBottomToolbar(new AcantoNumRecordsPerPageToolbar(this, rowsPerPage));
	}
	
	@Override
	protected Item<T> newRowItem(String id, int index, IModel<T> model)
	{
		return new OddEvenItem<T>(id, index, model);
	}
	
	protected WebMarkupContainer newFiltersContainer(final String id)
	{
		return new WebMarkupContainer(id);
	}
	
}
